package org.jgs1904.rabbitmq.workqueues;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.jgs1904.utils.RabbitMqUtils;

/**
 * @author: 默苍璃
 * @date: 2023-05-31 17:51
 * <p>
 * 工作线程2
 */
public class Worker02 {

    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String receivedMessage = new String(delivery.getBody());
            System.out.println("Worker02 接收到消息:" + receivedMessage);
        };

        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println(consumerTag + "消费者取消消费接口回调逻辑");
        };

        System.out.println("Worker02 消费者启动等待消费.................. ");

        channel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);

    }

}
